/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package feuerwehr;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 *
 * @author gundlape
 */
public class ReadParameter {
    
    /**
     * Startparameter aus einem ini File lesen
     * @param iniFile Die ini-Datei
     */
    public static void readFromFile(String iniFile) {
        try {
            BufferedReader in = new BufferedReader(new FileReader(iniFile));
            String str;
            while ((str = in.readLine()) != null) {
                if (str.startsWith("USER=")) {
                    strUsername = str.substring(5, str.length());
                }
                if (str.startsWith("PASS=")) {
                    strPassword = str.substring(5, str.length());
                }
                if (str.startsWith("URL=")) {
                    strURL = str.substring(4, str.length());
                }
                if (str.startsWith("PROXYPORT=")) {
                    strProxyPort = str.substring(10, str.length());
                }
                if (str.startsWith("PROXYHOST=")) {
                    strProxyHost = str.substring(10, str.length());
                    System.err.println("DEBUG>> PROXYHOST: " + strProxyHost);
                }
            }
            in.close();
        } catch (IOException err) {
            System.err.println("ERROR>> IOException: " + err);
        }
    }

    /**
     * Den gelesenen Parameter zurückgeben
     * @param str Name des gesuchten Parameters
     * @return Der Wert aus der ini Datei
     */
    public static String getParameter(String str) {
        switch (str) {
            case "user":    return strUsername;
            case "pass":    return strPassword;
            case "url":     return strURL;
            case "phost":   return strProxyHost;
            case "pport":   return strProxyPort;
        }
        return "";
    }
    
    private static String strUsername = "";
    private static String strPassword = "";
    private static String strURL = "";
    private static String strProxyHost = "";       
    private static String strProxyPort = "";       
}
